from DrissionPage import ChromiumPage
from DrissionPage.common import By
import logging as log
log.basicConfig(level=log.INFO,format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

info = {}
info['username'] = "17625994713"
info['password'] = "Wszyj0713sjxy"

page = None


def login():
    # 输入用户名
    page.ele('x://input[@placeholder="请输入账号"]').input(info['username'])
    # 输入密码
    page.ele('x://input[@placeholder="请输入密码"]').input(info['password'])
    # 登录
    page.ele('x://div[contains(@class,"login")]//div[contains(text(),"登录")][@class="btn_primary "]').click()



def main():
    # 用 d 模式创建页面对象（默认模式）
    global page
    page = ChromiumPage()
    page.get('https://www.bilibili.com/')
    login_elem = page.ele((By.XPATH,'//div[@class="header-login-entry"]//span[contains(text(),"登录")]'),timeout=3)
    if not login_elem:
        log.info("已经登录")
        return
    log.info("开始登录")
    login_elem.click()
    login()


if __name__=="__main__":
    main()